<!DOCTYPE html>
<html>
<head>
<head/>
<div th:include="base-libs :: base-libs" />
<div th:include="common/yljg-modal :: yljg-modal" />
<div th:include="common/common-export :: common-export" />
<title>服务管理</title>
<style type="text/css">

/* .form-table button{
	margin-top: 6px;
} */
.tabs-wrap>.tabs>li>a{
	border-left:1px solid #438EB9!important;
	border-right:1px solid #438EB9!important;
	border-top:1px solid #438EB9!important;
}
.laydate-icon{
	border:1px solid #b6b6b6
}
</style>
</head>
<script th:inline="javascript">
	/**用户信息*/
	var userInfo = [[${userInfo}]];
</script>
<script type="text/javascript">
$(function() {
	$(this).registerManagerPage();
	enterToQuery(queryForm);
 	initView();
});

function queryForm() {
	$("#fwForm").datagrid("reload");
}

function queryLyForm() {
	$("#fwlyForm").datagrid("reload");
}

function initView()
{
	$("#combogridYljg").combogrid(comboDatagridOption("xj"));
	$("#combogridYljg1").combogrid(comboDatagridOption("ly"));
	//$(".cacheTable").CacheForSelect();
	var select = StoreCache.removeCache("SELECT_FWGL");
	if(select){
		$("#tabbleFwgl").tabs("select",parseInt(select));
	}
	$("#fwForm").datagrid(datagridOption("xj"));
	$("#fwlyForm").datagrid(datagridOption("ly"));
	
	/**加载tabs*/
	$("#tabbleFwgl").tabs({    
	    border:false,
	    fit: true,
	    tabWidth: "200",
	    onSelect:function(title, index){  
	    			if(index==0){
	    				enterToQuery(queryForm);
	    			}else{
	    				enterToQuery(queryLyForm);
	    			}
				}
	    	});
	
	/**禁用修改按钮*/
	//$("#btnUpdate").attr("disabled", "disabled");
	
	/**加载选择方法*/
	//SelectCheckBox("YLTID","fwForm", "btnUpdate", opt);
	
	/**更新*/
	$("#btnUpdate").on("click", function(){
		var info = $("#fwForm").datagrid("getSelections");
		if(validate(info)){
			if(info.length == 1){
				info = info[0];
				if(info["SFSX"] == "0"){
					$.QuickUrlUtils.redirectUrl("manager.html?FWGLID="+info["FWGLID"]+"&PTJGID="+info["TGFWJGID"]);
				}else{
					$.QuickAlert.alertFail({content : "该服务已生效，不可修改！"});
				}
			}else{
				$.QuickAlert.alertFail({content : "请选中单个服务！"});
			}
		}else{
			$.QuickAlert.alertFail({content : "请选中服务！"});
		}
	});
	
	/**查询*/
	$("#btnQuery").on("click", function(){
		queryForm();//$("#fwForm").datagrid("reload");
	});
	
	/**查询*/
	$("#btnQuery1").on("click", function(){
		queryLyForm();//$("#fwlyForm").datagrid("reload");
	});
	
	/**新建*/
	$("#btnAdd").on("click", function(){
		$.QuickUrlUtils.redirectUrl("manager.html?YLJGID="+userInfo["PTJGID"]);
	});
	
	
	
	/**导出*/
	$("#btnExport").on("click", function(){
		$(".PTJGID").val(userInfo.PTJGID);
		$("#exportForm").submit();
	});
	
	$("#btnExport1").on("click", function(){
		$(".PTJGID").val(userInfo.PTJGID);
		$("#exportForm1").submit();
	});
}

function datagridOption(lx){
	var barTool;
	if(lx=="xj"){
		barTool = $("#dgFormToolbar");
	}
	else if(lx=="ly"){
			barTool = $("#dgFormToolbar1");
	}
	dgFormToolbar
	var opt ={
			idField : "FWGLID",
			uniqueId: "FWGLID",
			striped : true,
			border:false,
			toolbar : barTool,
			columns : [[
// 				{
// 					field: "checkStatus",
// 					checkbox: true
// 				},
				{
					field : "FWMC",
					width: 150,
					align: "center",
					title : "服务名称"
				},
				{
					field : "TGFWJGMC",
					width: 150,
					align: "center",
					title : "提供服务机构"
				},
				
				{
					field : "YLJGMC",
					width: 150,
					align: "center",
					title : "接收服务机构"
				},
				{
					field : "YLTLXMC",
					width: 100,
					align: "center",
					title : "医联体类型"
				},
				{
					field : "YQFWSJ",
					width: 100,
					align: "center",
					title : "预期服务时间"
				},
				{
					field : "FWNR",
					width: 250,
					align: "center",
					title : "服务内容",
					formatter : function(value, row, index){
						return "<span title='"+value+"'>"+value+"</span>";
					}
				},
				{
					field : "SFSX",
					width: 100,
					align: "center",
					title : "状态",
					formatter : function(value, row, index){
						if(value=="0"){
							return "已新建";
						}else if(value=="1"){
							return "已服务";
						}
					}
				},
				{
					field : "cz",
					width: 100,
					align: "center",
					title : "操作",
					formatter : function(value, row, index) {
						var tool;
						if(lx=="xj"){
							if(row["XZBL"]=="1"){
								tool = $("#tableToolBarTalk").html();
							}else{
								tool = $("#tableToolBarDetail").html();
							}
							
						}
						else if(lx=="ly"){
							if(row["XZBL"]=="1"){
								tool = $("#tableToolBarTalk").html();
							}else{
								if(row["SFSX"] == "0"){
									tool = $("#tableToolBarLy").html();
								}else{
									tool = $("#tableToolBarDetail").html();
								}
							}
						}
						
						return tool.replace(/#index#/g,index).replace(/#lx#/g,lx);
					}
				}
			]]
			,pagination : true
			,pageNumber: 1
			,pageSize: 10
			,fit: true
			,fitColumns: true
			,singleSelect: true
			,rownumbers: true
			,method : "post"
			,url: contextRoot+"fwgl/queryPage.service"
			,onBeforeLoad:function(params){
				if(lx=="xj"){
					params["YLJGID"] = $("#combogridYljg").combogrid("getValue");
					params["FWMC"] = $("#FWMC").val();
					params["FWSJ"] = $("#FWSJ").val();
					params["TGFWJGID"] = userInfo["PTJGID"];
				}
				else if(lx=="ly"){
					params["TGFWJGID"] = $("#combogridYljg1").combogrid("getValue");
					params["FWMC"] = $("#FWMC1").val();
					params["FWSJ"] = $("#FWSJ1").val();
					params["YLJGID"] = userInfo["PTJGID"];
				}
				return params;
			}
		};
		return opt;
}

function comboDatagridOption(lx){
	var opt ={
	        height: 30
	        ,panelWidth: 500
	        ,singleSelect: true
	        ,pagination: true
	        ,idField: 'PTJGID'
	        ,textField: 'YLJGMC'
	        ,mode: "remote"
	        ,url: contextRoot + "yljgxx/queryPage.service"
			//,readonly: readonly
	        //,hasDownArrow: !readonly
			,delay: 1000
	        ,reversed: true
	        ,columns:[[
	            {
	                field:'YLJGMC'
	                ,title:'机构名称'
	                ,width:240
	                ,align: 'center'
	            }
	            ,{
	                field:'XZQHMC'
	                ,title:'行政区划'
	                ,width:80
	            }
	            ,{
	                field:'WSJGLBMC'
	                ,title:'机构类别'
	                ,width:80
	            }
	            ,{
	                field:'YYDJMC'
	                ,title:'机构等级'
	                ,width:80
	            }
	        ]]
	        ,onBeforeLoad: function(queryParams) {
	            var url = $(this).datagrid("options")["url"];
				/*URL不等空时再发送请求*/
	            if (!StringUtils.isEmpty(url)) {
	                queryParams["pageSize"] = queryParams["rows"];
	                queryParams["pageNumber"] = queryParams["page"];
	                if(lx == "xj"){
	                	 queryParams["YLJGMC"] = queryParams["q"];
	                }
	                else if(lx == "ly"){
	                	 queryParams["YLJGMC"] = queryParams["q"];
	                }
	               
	                return true;
	            }else{
	                return false;
	            }
	        }
			,onChange: function(newValue, oldValue){
	            /*新增响应改变事件*/
	           /*  if(!$("#formYljgry").data("yljgry")){
	                var value = $("#combogridYljg").combogrid("grid").datagrid("getSelected");
	                if(!value){
	                    $("#KS").empty();
	                }else if(value["PTJGID"] != oldValue){
	                    $("#KS").empty();
	                    queryKsxx(value["PTJGID"]);
	                    $("#PTJGID").val(value["PTJGID"]);
	                    $("#YLJGDM").val(value["YLJGDM"]);
	                }
				} */
				
			}
	    };
	return opt;
}

/**详细按钮*/
function detail(index,lx){
	var obj;
	if(lx=="xj"){
		obj = $("#fwForm");
		StoreCache.setCache("SELECT_FWGL",0);
	}else{
		StoreCache.setCache("SELECT_FWGL",1);
		obj = $("#fwlyForm");
	}
	/**清除所有选择*/
	$(obj).datagrid("clearSelections");
	/**选中当前行*/
	$(obj).datagrid("selectRow", index);
	/**获取选中行数据*/
	var row = $(obj).datagrid("getSelected", index);
	$.QuickUrlUtils.redirectUrl("detail.html?FWGLID="+row["FWGLID"]+"&PTJGID="+row["TGFWJGID"]);
}

/**讨论按钮*/
function talk(index,lx){
	var obj;
	if(lx=="xj"){
		StoreCache.setCache("SELECT_FWGL",0);
		obj = $("#fwForm");
	}else{
		StoreCache.setCache("SELECT_FWGL",1);
		obj = $("#fwlyForm");
	}
	/**清除所有选择*/
	$(obj).datagrid("clearSelections");
	/**选中当前行*/
	$(obj).datagrid("selectRow", index);
	/**获取选中行数据*/
	var row = $(obj).datagrid("getSelected", index);
	$.QuickUrlUtils.redirectUrl("talk.html?FWGLID="+row["FWGLID"]+"&PTJGID="+row["TGFWJGID"]);
}

function lvyue(index){
	StoreCache.setCache("SELECT_FWGL",1);
	/**清除所有选择*/
	$("#fwlyForm").datagrid("clearSelections");
	/**选中当前行*/  
	$("#fwlyForm").datagrid("selectRow", index);
	/**获取选中行数据*/
	var row = $("#fwlyForm").datagrid("getSelected", index);
	$.QuickUrlUtils.redirectUrl("lvyue.html?FWGLID="+row["FWGLID"]+"&PTJGID="+row["TGFWJGID"]);
}


/**获取状态*/
function getZt(zt){
	if(zt == "01"){
		zt = "暂存";
	}
	else if(zt == "02"){
		zt = "待接收";
	}
	else if(zt == "03"){
		zt = "已签约";
	}
	else if(zt == "04"){
		zt = "拒绝";
	}
	else if(zt == "05"){
		zt = "已到期";
	}
	return zt;
}

/**校验是否选中*/
function validate(info){
	if(StringUtils.isEmpty(info)){
		return false;
	}else{
		return true;
	}
}

var start = {
	    elem: '#KSSJ',
	    choose: function(datas){
	    	end.min = datas; //开始日选好后，重置结束日的最小日期
	    	end.start = datas; //将结束日的初始值设定为开始日
	    }
	};
var end = {
	    elem: '#JSSJ',
	    choose: function(datas){
	    	start.max = datas; //结束日选好后，重置开始日的最大日期
	    }
	};
</script>

<body >
<div id="tabbleFwgl" class="easyui-tabs" data-options="fit:true">   
    <div title="新建服务" style="display:none;">
	    <div class="easyui-layout" fit="true">
		    <!-- <div region="north" style="border: none; overflow: hidden;">
				<h4 class="h4-title" style="margin:0;padding:0;font-size: 18px;">
					服务管理
				</h4>
			</div> -->
			<div region="center" style="border: none;" >
				
				<div id="dgFormToolbar" style="background: white;">
					<form id="exportForm" action="export.service" enctype="multipart/form-data">
						<table class="form-table" style="margin:0;padding:0;width:100%">
							<tr>
								<td class="td-text">服务名称：</td>
								<td class="td-content">
									<input type="hidden" name="TGFWJGID" class="PTJGID" />
									
									<input id="FWMC" name="FWMC" class="form-control" >
								</td>
								</td>
								<td class="td-text">接收服务机构：</td>
								<td class="td-content">
									<input id="combogridYljg" name="YLJGID" class="form-control dataField"  style="width: 90%;"/>
								</td>
								
								<td class="td-text">服务时间：</td>
								<td class="td-content">
									 <input id="FWSJ" name="FWSJ" style="width:85%;height:30px;"
										class="input-text laydate-icon dataField" onclick="laydate()" />
									<!-- - <input id="JSSJ" name="JSSJ" style="width:35%;height:30px;"
										class="input-text laydate-icon dataField" onclick="laydate(end)" /> -->
								</td>
								<td class="td-text" style="text-align:center;width:160px;">
									<button id="btnQuery" class="btn btn-info" type="button" >查询</button>
									<button id="btnExport" class="btn btn-info" type="button">导出</button>
								</td>
							</tr>
						</table>
					</form>
					<div style="margin:10px 10px auto 0px;">
						<button id="btnAdd" class="btn btn-info" type="button">新建服务</button>
						<button id="btnUpdate" class="btn btn-info" type="button">修改服务</button>
					</div>
				</div>
				<div class="easyui-layout" style="border: none;" fit="true">
					<div region="center" style="border: none;">
						<table id="fwForm">
						</table>
					</div>
				</div>
			</div>
		  </div>
    </div>
    <div title="履约服务" style="display:none;">
	    <div class="easyui-layout" fit="true">
		    <!-- <div region="north" style="border: none; overflow: hidden;">
				<h4 class="h4-title" style="margin:0;padding:0;font-size: 18px;">
					服务管理
				</h4>
			</div> -->
			<div region="center" style="border: none;">
				<div id="dgFormToolbar1" style="background: white;">
					<form id="exportForm1" action="export.service" enctype="multipart/form-data">
						<table class="form-table" style="margin:0;padding:0;width:100%">
							<tr>
								<td class="td-text">服务名称：</td>
								<td class="td-content">
									<input type="hidden" name="YLJGID" class="PTJGID" />
									
									<input id="FWMC1" name="FWMC" class="form-control" >
								</td>
								</td>
								<td class="td-text">提供服务机构：</td>
								<td class="td-content">
									<input id="combogridYljg1" name="TGFWJGID" class="form-control dataField"  style="width: 90%;"/>
								</td>
								
								<td class="td-text">服务时间：</td>
								<td class="td-content">
									 <input id="FWSJ1" name="FWSJ" style="width:85%;height:30px;"
										class="input-text laydate-icon dataField" onclick="laydate()" />
									<!-- - <input id="JSSJ1" style="width:35%;height:30px;"
										class="input-text laydate-icon dataField" onclick="laydate(end)" /> -->
								</td>
								<td class="td-text" style="text-align:center;width:160px;">
									<button id="btnQuery1" class="btn btn-info" type="button" >查询</button>
									<button id="btnExport1" class="btn btn-info" type="button">导出</button>
								</td>
							</tr>
						</table>
					</form>
					<!-- <div style="margin:10px 10px auto 0px;">
						<button id="btnExport1" class="btn btn-info" type="button">导出</button>
						<button id="btnUpdate" class="btn btn-info" type="button">履约</button>
					</div> -->
				</div>
				<div class="easyui-layout" style="border: none;" fit="true">
					<div region="center" style="border: none;">
						<table id="fwlyForm">
						</table>
					</div>
				</div>
			</div>
		  </div>
    </div>
</div>

</body>
<script type="text/html" id="tableToolBarDetail">
<a class="tableToolBarBtn" href="javascript:detail(#index#,'#lx#')" title="详细" >详细</a>
</script>
<script type="text/html" id="tableToolBarTalk">
<a class="tableToolBarBtn" href="javascript:talk(#index#,'#lx#')" title="讨论" >讨论</a>
<a class="tableToolBarBtn" href="javascript:detail(#index#,'#lx#')" title="详细" >详细</a>
</script>
<script type="text/html" id="tableToolBarLy">
<a class="tableToolBarBtn" href="javascript:lvyue(#index#)" title="履约" >履约</a>
<a class="tableToolBarBtn" href="javascript:detail(#index#,'#lx#')" title="详细" >详细</a>
</script>
</html>



